<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     rwd_default
 * @copyright   Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php if(Mage::helper('themeframework/settings')->getContacts_MapEnable() == 1): ?>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.17&signed_in=true"></script>
    <?php
        $_generalAddress = nl2br(Mage::getStoreConfig('general/store_information/address'));
        $_generalStoreName = nl2br(Mage::getStoreConfig('general/store_information/name'));        
        $_configAddress =  Mage::helper('themeframework/settings')->getContacts_MapAddress('249 Ung Van Khiem, Phuong 25, Binh Thanh, Ho Chi Minh');        
        if(!$_configAddress){
            $_address = $_generalAddress;
        }else{
            $_address = $_configAddress;
        }
        $_address = str_replace(' ','+',$_address); 
        $_jsonCode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$_address.'&sensor=false');        
        $_jsonDecode = json_decode($_jsonCode);        
        $_lat = $_jsonDecode->results[0]->geometry->location->lat;        
        $_lng = $_jsonDecode->results[0]->geometry->location->lng;        
        $_imageUrl =  Mage::getbaseUrl("media").Mage::helper('themeframework/settings')->getContacts_MapImage('em0131/variations/gmap_icon.png');        
    ?>
    
    <script type="text/javascript">
        function initialize() {
    	var myLatlng = new google.maps.LatLng(<?php echo $_lat?>, <?php echo $_lng ?>);
    	var mapOptions = {
    		zoom: 10,
    		center: myLatlng
    	};
    	var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
        var contentString = '<?php echo Mage::helper('themeframework/settings')->getContacts_MapInfo($_generalStoreName) ?>';
    	var infowindow = new google.maps.InfoWindow({
    		content: contentString
    	});
        var image = '<?php echo $_imageUrl ?>';
    	var marker = new google.maps.Marker({
    		position: myLatlng,
    		map: map,
            icon: image,
    		title: '<?php echo $_generalStoreName ?>'
    	});
    	google.maps.event.addListener(marker, 'click', function() {
    		infowindow.open(map, marker);
    	});
    }
    google.maps.event.addDomListener(window, 'load', initialize);
    </script>
    <div id="map-canvas" style="width: <?php echo Mage::helper('themeframework/settings')->getContacts_MapWidth() ?>px; height: <?php echo Mage::helper('themeframework/settings')->getContacts_MapHeight(500) ?>px"></div>
<?php endif;?>